package com.example.homework3;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

public class CustomDialog extends DialogFragment
{
    private CustomDialog.NotifyDialogListener listener;
    public  interface NotifyDialogListener
    {
        public void onDialogPositiveClicked(String gender);
    }

    public void SetLister(CustomDialog.NotifyDialogListener listener)
    {
        this.listener=listener;
    }


    public Dialog onCreateDialog(Bundle savedIntanceState)
    {
        AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
        LayoutInflater inflater=requireActivity().getLayoutInflater();
        View view=inflater.inflate(R.layout.mine1,null);
        View textView=view.findViewById(R.id.textView);
        View textView2 = view.findViewById(R.id.textView2);

        builder.setView(view)
                .setTitle("请阅读以下内容")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        listener.onDialogPositiveClicked(textView.toString());
                        listener.onDialogPositiveClicked(textView2.toString());
                        Toast.makeText(getActivity().getApplicationContext(),"你点击了确定",Toast.LENGTH_SHORT).show();
                    }
                })
                .setNeutralButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Toast.makeText(getActivity().getApplicationContext(),"你点击了取消",Toast.LENGTH_SHORT).show();
                    }
                });
        return builder.create();
    }

}
